/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2022-10-15     zlj       the first version
 */
#if defined(A5158_EDITION)
#include <rtthread.h>
#include <rtdevice.h>

#include <string.h>
#include <stdlib.h>

#include "app_lcd_drv.h"


//extern charge_para_t charge_para;
extern lcd_display_info_t display_info;

#ifdef RT_USING_FINSH

static int lcd(int argc, char **argv)
{
    int value = 0;
    int result = RT_EOK;
    static rt_adc_device_t adc_device = RT_NULL;
    char *result_str;

    if (argc > 1) {
		if(!strcmp(argv[1], "page")){
            uint32_t page_val = atoi(argv[2]);
			lcd_page_set(page_val);
            rt_kprintf("lcd page set :%d\n", page_val);

        }else  if(!strcmp(argv[1], "light")){
            uint32_t light_val = atoi(argv[2]);
            lcd_cmd_backlight_set(light_val);
            rt_kprintf("lcd backlight set :%d\n", light_val);

        }else if(!strcmp(argv[1], "color")){
            uint32_t addr = atoi(argv[2]);
            uint32_t var = atoi(argv[3]);
            lcd_cmd_text_set(addr, ATTRIBUTE_STR_COLOR, &var);
            rt_kprintf("lcd color set :0x%x\n: 0x%x", addr, var);

        }else if(!strcmp(argv[1], "position")){
            uint32_t addr = atoi(argv[2]);
            uint32_t pos_x = atoi(argv[3]);
            uint32_t pos_y = atoi(argv[4]);
            rt_kprintf("lcd position set addr:%x pos_x:%d pos_y:%d\n", addr, pos_x, pos_y);
            pos_y = (pos_x << 16) + pos_y;
            lcd_cmd_text_set(addr, ATTRIBUTE_STR_POSITION, &pos_y);

        }else if(!strcmp(argv[1], "position_num")){
            uint32_t pos_x = atoi(argv[2]);
            uint32_t pos_y = atoi(argv[3]);
            rt_kprintf("lcd  num position set pos_x:%d pos_y:%d\n", pos_x, pos_y);
            lcd_charge_num_position_set(pos_x,pos_y);

        }else if(!strcmp(argv[1], "breath")){
            uint8_t enable = atoi(argv[2]);
            uint32_t frequency = atoi(argv[3]);
            lcd_page_breathe_set(enable, frequency);
            rt_kprintf("lcd breath set:%s frequent:%d\n", (enable == 0)?"disable":"enable", frequency);

        }else if(!strcmp(argv[1], "size")){
            uint32_t attribute_addr = atoi(argv[2]);
            uint8_t size = atoi(argv[3]);
            //lcd_page_breathe_set(enable, frequency);
            lcd_string_size_set(attribute_addr, size);
					rt_kprintf("lcd size set:attribute_addr %x size %d \n", attribute_addr, size);

        }else if(!strcmp(argv[1], "value_set")){
            rt_kprintf("value set:%d", atoi(argv[3]));
            if(!strcmp(argv[2], "power")){
				lcd_display_info_set(TYPE_CHARGE_POWER, atoi(argv[3]));
            }else if(!strcmp(argv[2], "time")){
				lcd_display_info_set(TYPE_CHARGE_TIME, atoi(argv[3]));
            }else if(!strcmp(argv[2], "fee")){
				lcd_display_info_set(TYPE_CHARGE_FEE, atoi(argv[3]));
            }else if(!strcmp(argv[2], "energy")){
				lcd_display_info_set(TYPE_CHARGE_ENERGY, atoi(argv[3]));
            }else if(!strcmp(argv[2], "cost")){
				lcd_display_info_set(TYPE_DEAL_COST, atoi(argv[3]));
            }else if(!strcmp(argv[2], "price_future")){
				lcd_display_info_set(TYPE_PRICE_FUTURE, atoi(argv[3]));
            }else if(!strcmp(argv[2], "price_current")){
				lcd_display_info_set(TYPE_PRICE_CURRENT, atoi(argv[3]));
            }else if(!strcmp(argv[2], "error_code")){
				lcd_display_info_set(TYPE_ERROR_CODE, atoi(argv[3]));
            }else if(!strcmp(argv[2], "reserve_id")){
				lcd_display_info_set(TYPE_RESERVE_ID, atoi(argv[3]));
            }
			else{
                rt_kprintf("Usage error,please use:lcd value_set <power/time/fee/energy> <value eg:12345>");
            }
        }else {
            rt_kprintf("Unknown command. Please enter 'lcd' for help\n");
        }    
    } else {
        rt_kprintf("Usage: \n");
        rt_kprintf("lcd str <addr> <string>\n");
        rt_kprintf("lcd icon <addr> <value>\n");
        rt_kprintf("lcd page <value>\n");
        rt_kprintf("lcd color <addr> <value>\n");
        rt_kprintf("lcd light <value>\n");
        rt_kprintf("lcd position <addr> <pos_x> <pos_y>\n");
        rt_kprintf("lcd value_set <power/time/fee/energy> <value>\n");
        rt_kprintf("lcd breath <0/1> <freq>\n");
        rt_kprintf("\n");
        result = -RT_ERROR;
    }
    return RT_EOK;
}
MSH_CMD_EXPORT(lcd, lcd function);

#endif /* RT_USING_FINSH */
#endif